package com.hailian.fintech.hlhouse_statusserver.web;

import com.hailian.fintech.hlhouse_statusserver.vo.ResultEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class UploadController {
    @RequestMapping("upload")
    public ResultEntity upload(MultipartFile file){
        String originalFilename = file.getOriginalFilename();
        String fileName = UUID.randomUUID() + "_" + originalFilename;
        File destFile = new File("D:\\pic", fileName);
        try {
            file.transferTo(destFile);
            String s = "http://127.0.0.1:8088/img/" + fileName;
            return  ResultEntity.ok(s);

        } catch (IOException e) {
            e.printStackTrace();
        }
        return ResultEntity.ok("图片地址错误");
    }
}
